Re: [SQL] locked my keys in the car

Поиск
Список
Период
Сортировка
От lynch@lscorp.com (Richard Lynch)
Тема Re: [SQL] locked my keys in the car
Дата
Msg-id v02140b17b1eb70a21315@[207.152.64.133]
обсуждение исходный текст
Ответы Re: [SQL] locked my keys in the car  (Thomas Good <tomg@q8.nrnet.org>)
Список pgsql-sql
At 9:10 AM 8/3/98, Thomas Good wrote:

>Next I tried Richard Lynch's suggestion:
>SELECT id FROM table
>WHERE office = 'M' AND (case = 'A' OR case = 'I')
>ORDER BY date DESC;
>
>And this is definitely on the right track as I am now down to
>75 patients (thanks Rich).
>
>The 13 active cases (in what we loosely term reality) are amongst
>the 75 returned tuples.  Moreover, I can catch the 62 inactive cases
>listed amongst the output from Rich's query with:
>
>SELECT tr_id, tr_date FROM crtrd1
>WHERE tr_unit = 'SMA' AND (tr_type = 'T' OR tr_type = 'O')
>ORDER BY tr_date DESC;
>
>(In this instance, T=terminated and O=outgoing...)
>
>So my next question is:
>Is there a way, using SQL, to do the math on this, i.e., to rm the
>patients who appear twice - once in the first query, once in the second?
>(God forbid we re-admit the same patient at some future date!)

Well I'm confused.  Nothing new there, eh?
If all you want is active cases, why not:

select id from table where office = 'M' and case = 'A' order by date desc;

>In other words, can I somehow go about rm'ing those patients who have
>a tr_type of T or O - with a tr_date that is > the tr_date of the entry
>with a tr_type of I or A?

You should be able to just mush all the stuff together in something like this

select distinct table.id from table, crtrd1 as entry, crtrd1 as exit where
    table.office = 'M' and (table.case = 'A' or table.case = 'I') and
    entry.tr_id = exit.tr_id and
    entry.tr_unit = 'SMA' and
    exit.tr_type != 'T' and exit..tr_type != 'O' and
    exit.tr_date > entry.tr_date and
    (entry.tr_type = 'A' or entry.tr_type = 'I');

I *THINK* this is kinda what you have asked for, but I don't really
understand for sure what your tables are, nor what you want to get out of
them...

--
--
-- "TANSTAAFL" Rich lynch@lscorp.com



В списке pgsql-sql по дате отправления:

Предыдущее
От: John Edstrom
Дата:
Сообщение: Re: [SQL] locked my keys in the car
Следующее
От: Thomas Good
Дата:
Сообщение: Re: [SQL] locked my keys in the car